package cn.zh.npro.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.ArrayList;

import cn.zh.npro.Item.GLItem;
import cn.zh.npro.R;


/**
 * Created by WYN on 2018/1/17 0017.
 */

public class GPadpter extends BaseAdapter {
    Context context;
    ArrayList<GLItem> arrayList;
    LayoutInflater inflater;

    public GPadpter(Context context, ArrayList<GLItem> arrayList){
      this.context=context;
      this.arrayList=arrayList;
      inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return arrayList.size();
    }

    @Override
    public Object getItem(int i) {
        return arrayList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        Holder holder=null;
        if (null==view){
            holder=new Holder();
            view=inflater.inflate(R.layout.gpa_layout,null,false);
            holder.tv=view.findViewById(R.id.tv);
            holder.lltem=view.findViewById(R.id.lltem);
            view.setTag(holder);
        }else {
            holder= (Holder) view.getTag();
         }
        holder.tv.setText(arrayList.get(i).getFlagName());
        if (0==arrayList.get(i).getType()){
            holder.lltem.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.graybg));
        }else {
            holder.lltem.setBackgroundDrawable(context.getResources().getDrawable(R.drawable.cprimbg));
        }

        return view;
    }


    public class Holder{
        LinearLayout lltem;
        TextView tv;
    }

}
